/**
 * Created by Administrator on 2018/12/1 0001.
 */
const express = require("express");
const router = express.Router();
const utils = require('../../public/utils');
const authorModel = require('../../model/author-model');

/*
* 获取所有作者
* */
router.post('/findAllAuthor',async(req,res) => {
    utils.tokenValid(req,res,() =>{
        authorModel.findDocs({},{},{},(docs) => {
            if(docs !== 9999) {
                res.send(utils.setJsonStyle('0', 'success',docs));
            }else {
                res.send(utils.setJsonStyle('9999', '查找失败'));
            }
        });
    })

})

/*
* 添加作者
* */
router.post('/addAuthor',(req,res) => {
    const author = new authorModel({
        name: 'htl',
    })
    author.addDocs((data) => {
        if(data !== 9999) {
            res.send(utils.setJsonStyle('0', 'success'));
        }else {
            res.send(utils.setJsonStyle('9999', '保存失败'));
        }
    })
})





module.exports = router;
